﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace Seminarska
{
    /// <summary>
    /// Interaction logic for Najava.xaml
    /// </summary>
    public partial class Najava : Window
    {
        private DataTable products;
        public Najava()
        {
            InitializeComponent();

            products = DB.GetProducts();
            cmbKorisnik.ItemsSource = products.DefaultView;
           

            Rect r = Properties.Settings.Default.Window;
            this.Top = r.Top;
            this.Left = r.Left;

        }

        private void btnNajava_Click(object sender, RoutedEventArgs e)
        {


            if (txtLozinka.Password == "2")
            {

                Kasa glStrana = new Kasa();
                glStrana.Show();
                Properties.Settings.Default.Window = this.RestoreBounds;
                Properties.Settings.Default.Save();
                this.Close();
            }
            else if (txtLozinka.Password == "1")
            {
                Menadzer glStrana = new Menadzer();
                glStrana.Show();
                Properties.Settings.Default.Window = this.RestoreBounds;
                Properties.Settings.Default.Save();
                this.Close();
            }
            else
            {
                ProcessOperation(((Button)sender).Name.ToString());
                MessageBox.Show("Внесена е погрешна лозинка!!!", "Error");
            }
        }


        private enum Operation
        {
            None,
            Subtract,
            OneX

        }
        private Operation LastOper;
        private string _display;
        private bool _erasediplay;
        private string _last_val;

        private string LastValue
        {
            get
            {
                if (_last_val == string.Empty)
                    return "0";
                return _last_val;

            }
            set
            {
                _last_val = value;
            }
        }

        private bool EraseDisplay
        {
            get
            {
                return _erasediplay;

            }
            set
            {
                _erasediplay = value;
            }
        }

        private string Display
        {
            get
            {
                return _display;
            }
            set
            {
                _display = value;
            }
        }

        private void DigitBtn_Click(object sender, RoutedEventArgs e)
        {
            string s = ((Button)sender).Content.ToString();
            

            char[] ids = s.ToCharArray();
            ProcessKey(ids[0]);
        }

        private void ProcessKey(char c)
        {
            if (EraseDisplay)
            {
                Display = string.Empty;
                EraseDisplay = false;
            }
            AddToDisplay(c);
        }

        private void UpdateDisplay()
        {
           txtLozinka.Password = Display;
        }

        private void AddToDisplay(char c)
        {
           
            if (c >= '0' && c <= '9')
            {
                Display = Display + c;
            }
          
            UpdateDisplay();
        }

        private void ProcessOperation(string s)
        {
            LastOper = Operation.None;
            Display = LastValue;
            UpdateDisplay();

        }

        private void btnC_Click(object sender, RoutedEventArgs e)
        {
            ProcessOperation(((Button)sender).Name.ToString());
           
            
        }


        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Properties.Settings.Default.Window = this.RestoreBounds;
            Properties.Settings.Default.Save();
        }

        private void btn1_TouchEnter(object sender, TouchEventArgs e)
        {
            string s = ((Button)sender).Content.ToString();
            

            char[] ids = s.ToCharArray();
            ProcessKey(ids[0]);
        }




    }
}

